package com.chinatsp.onlineapp.presenter;

import tsp.cn.http.BaseIDao;
import tsp.cn.http.HttpConfig;
import tsp.cn.http.interfac.INetResult;
import tsp.cn.http.tools.LogUtil;
import tsp.cn.http.tools.T;
import android.content.Context;

import com.chinatsp.onlineapp.base.Config;
import com.chinatsp.onlineapp.bean.ReverseGeocod;
import com.google.gson.Gson;

/**
 * 根据经纬度获取城市名称
 */

public class ReverseGeocodeDao extends BaseIDao {

	private ReverseGeocod reverseGeocod;
	private Context context;

	public ReverseGeocodeDao(Context context, INetResult iNetResult) {
		super(context, iNetResult);
		this.context = context;
	}

	/**
	 * 数据
	 */
	public ReverseGeocod getReverseGeocod() {
		return reverseGeocod;
	}

	/**
	 * 得到结果后，对结果处理逻辑
	 * 
	 * @param result
	 * @param requestCode
	 */
	@Override
	public void onRequestSuccess(String result, int requestCode) {
		LogUtil.d( "ReverseGeocodeDao onRequestSuccess");
		reverseGeocod = new Gson().fromJson(result, ReverseGeocod.class);
	}

	/**
	 * 获取城市名称
	 * 
	 * @param lat
	 *            纬度
	 * @param lng
	 *            经度
	 */
	public void getReverseGeocode(String lat, String lng) {

		StringBuilder strBuilder = new StringBuilder();
		strBuilder.append(HttpConfig.appendString());
		strBuilder.append(Config.API_REVERS_GEOCODE);
		strBuilder.append(lat);
		strBuilder.append("/");
		strBuilder.append(lng);
		strBuilder.append("/");

		getRequest(strBuilder.toString(), Config.CODE_REVERS_GEOCODE);
	}
}
